import { ExecutionContext, NestInterceptor, CallHandler } from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Injectable } from '@nestjs/common';

@Injectable()
export class ResponseInterceptor implements NestInterceptor {
  // 拦截器 next 是下一个拦截器
  intercept(_context: ExecutionContext, next: CallHandler): Observable<any> {
    return next.handle().pipe(
      map((data) => {
        return {
          data: data,
          code: 200,
          message: 'success',
        };
      }),
    );
  }
}
